package com.xlt.activiti.one;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricActivityInstanceQuery;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;

import java.util.List;

public class ActivitiHistroy {
    public static void  histroyQuery(String key){
        // 1.得到processEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 2.获取repositoryService
        RepositoryService repositoryService = processEngine.getRepositoryService();
        // 2.得到历史服务
        HistoryService historyService = processEngine.getHistoryService();

        // 3.得到historicActivitiInstanceQuery
        HistoricActivityInstanceQuery historicActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery();
        String deploymentId = "25001";
        // 4.执行查询
        List<HistoricActivityInstance> list = historicActivityInstanceQuery.processInstanceId(deploymentId)
                .orderByHistoricActivityInstanceStartTime().asc().list();

        // 5。遍历输出
        for(HistoricActivityInstance instance :list){
            System.out.println(instance.getActivityId());
            System.out.println(instance.getProcessInstanceId());
            System.out.println(instance.getActivityName());
            System.out.println(instance.getProcessDefinitionId());
        }

    }
}
